home *** CD-ROM | disk | FTP | other *** search
- /*
- * Code for PACK ID -4096 to be used with the Chooser to set the
- * printing port options. Set the Flags longword in the PACK
- * resource to 0400E000 after building the PACK resource to make
- * sure we get the right-hand button message.
- */
-
- #include <WindowMgr.h> /* includes QuickDraw.h, MacTypes.h */
- #include <DialogMgr.h>
- #include "prglobals.h"
- /*
- * Resources which are standard type and accessed by the PACK -4096 resource
- * have ID # RES1ID. Resources which are non-standard type and/or belong
- * without a doubt to our driver code are accessed with RES2ID. These include
- * the Stng resource and our PREC #-8192. (IM 4 says standard resource types
- * to be used by this PACK resource should have IDs in the range -4080 to
- * -4065.)
- */
-
- /* Printer Setup Dbox item numbers… */
- #define SAVEITEM 1
- #define MODEM 5
- #define PRINTER 6
- #define BAUDBUTTON 8
- #define EOLITEM 11
- #define INITITEM 12
- #define TOPITEM 13
- #define EOPITEM 14
- #define EOFITEM 15
- #define CTSITEM 19
- #define XONXOFFITEM 20
- #define CANCELITEM 21
- #define NUMSTRINGS 5
- #define RESPAD 24
-
- pascal OSErr main(message,caller,objname,zonename,p1,p2)
- int message,caller;
- StringPtr objname,zonename;
- long p1,p2;
- {
- if (message == buttonMsg){
- prsetup();
- }
- return (noErr);
- }
- pushradiobutton(thedialog,itemhit,first,last) /* push a radio Button */
- DialogPtr thedialog; /* set itemhit, unset */
- int itemhit,first,last; /* all others in range */
- {
- int itemtype,i;
- Handle itemhandle; /* Does check boxes, too. */
- Rect itemrect; /* (when range is 1 in size.) */
- if(first ==0) return;
- for(i=first-1;last-i++;){
- GetDItem(thedialog,i,&itemtype,&itemhandle,&itemrect);
- if(i == itemhit) SetCtlValue(itemhandle,1);
- else SetCtlValue(itemhandle,0);
- }
- }
- prsetup()
- {
- DialogPtr printdialog;
- WindowPtr tempport;
- int itemhit,i,baudtype,edittype,donetype;
- Handle bauditem,doneitem,edititem;
- Rect baudbox,donebox,editbox;
- Str255 thestring;
- unsigned char *strptr;
- long length,result;
- BAUDS **mybauds;
- Pfg settings;
- StrList mystrings;
- mybauds = (BAUDS **)GetResource('PREC',RES2ID);
- if(mybauds == nil) return;
- if ((settings = (Pfg)(GetResource('Stng',RES2ID))) == nil ||
- (mystrings = (StrList)
- (GetResource('STR#',RES1ID))) == nil)
- return;
- if (pbaud<0 || pbaud>9) pbaud = 0;
- if((printdialog = GetNewDialog(RES1ID, 0L,(WindowPtr) -1)) == nil)
- return;
- GetDItem(printdialog,BAUDBUTTON,&baudtype,&bauditem,&baudbox);
- GetDItem(printdialog,SAVEITEM,&donetype,&doneitem,&donebox);
- SetCTitle(bauditem,((*mybauds)+pbaud)->label);
- /* This gets the printer control strings from a string list,
- * then sets the editText items in the dialog box to contain
- * the strings.
- */
- strptr = &((*mystrings)->thestrings[0]);
- for(i = EOLITEM-1;EOFITEM - i++;){
- GetDItem(printdialog,i,&edittype,&edititem,&editbox);
- SetIText(edititem,strptr);
- strptr += (*strptr) + 1;
- }
- GetPort(&tempport);
- SetPort(printdialog);
- ShowWindow(printdialog);
- PenSize(4,4); /* Time to frame some buttons. */
- InsetRect(&donebox,-5,-5);
- FrameRoundRect(&donebox,16,16);
- PenSize(2,2);
- InsetRect(&baudbox,-3,-3);
- FrameRoundRect(&baudbox,12,12);
- pushradiobutton(printdialog, pport + MODEM,MODEM,PRINTER);
- pushradiobutton(printdialog,CTSITEM + XonXoff,CTSITEM,
- XONXOFFITEM);
- itemhit = 0;
- while(itemhit !=1){
- ModalDialog(0L,&itemhit);
- switch(itemhit){
- /* Port change. It might be nice to check and see
- * whether AppleTalk is active if the user selects
- * the Printer Port… */
- case MODEM:
- case PRINTER:
- pport = itemhit - MODEM;
- pushradiobutton(printdialog,itemhit,
- MODEM,PRINTER);
- break;
- case BAUDBUTTON: /* next baud rate change */
- /* Ten radio buttons would be just too much. */
- if(++pbaud == 10) pbaud = 0;
- SetCTitle(bauditem,((*mybauds)+pbaud)->label);
- break;
- case CTSITEM:
- case XONXOFFITEM:
- XonXoff = itemhit - CTSITEM;
- pushradiobutton(printdialog,
- itemhit,CTSITEM,XONXOFFITEM);
- break;
- case CANCELITEM:
- DisposDialog(printdialog);
- SetPort(tempport);
- return;
- break;
- }
- }
- /* The user has set the baud rate and the port, and also possibly
- * edited the printer control strings. Since we used ModalDialog()
- * with no filterproc we don't know whether any of the strings have
- * been changed. Therefore we just rebuild the whole string list.
- * First, determine the length.
- */
- length = (long) (sizeof(int)+RESPAD);
- for(i = EOLITEM-1;EOFITEM - i++;){
- GetDItem(printdialog,i,&edittype,&edititem,&editbox);
- GetIText(edititem,thestring);
- length += (long) thestring[0];
- }
- /* Size might have changed, so we unlock the handle and attempt to
- * resize it. */
- asm{
- move.l mystrings,a0 ;; This is to save loading MacTraps
- _HUnlock
- move.l mystrings,a0
- move.l length,d0
- _SetHandleSize
- move.l mystrings,a0
- _GetHandleSize
- move.l d0,result
- }
- if ( result != length ){ /* Abort on error. */
- DisposDialog(printdialog);
- SetPort(tempport);
- return(FALSE);
- }
- asm{
- move.l mystrings,a0
- _HNoPurge
- move.l mystrings,a0
- _HLock
- }
- /* Rebuild the STR# from the item list. */
- strptr = &((*mystrings)->thestrings[0]);
- for(i = EOLITEM-1;EOFITEM - i++;){
- GetDItem(printdialog,i,&edittype,&edititem,&editbox);
- GetIText(edititem,strptr);
- strptr += (*strptr) + 1;
- }
- DisposDialog(printdialog);
- SetPort(tempport);
- ChangedResource(settings);
- ChangedResource(mystrings);
- WriteResource(settings);
- WriteResource(mystrings);
- return;
- }
-